

using System;
using System.Collections.Generic;
using System.Text;
using EntityLayer;
using System.Data;
using DataAccessLayer;
using InfraStructureLayer;

namespace DataLayer
{
	public class datArticles
	{
		public datArticles()
		{
		}
		
		#region  Code Factory Generated Methods
		public void DeleteArticlesByArticleId(entArticles parEntArticles, DbConnector parDbConnector)
		{
			DbParamCollection insDbParamCollection = new DbParamCollection();
			insDbParamCollection.Add("@pArticleId",parEntArticles.ArticleId);
			parDbConnector.ExecuteNonQuery("DeleteArticlesByArticleId",insDbParamCollection);
		}
		public void InsertArticles(entArticles parEntArticles, DbConnector parDbConnector)
		{
			DbParamCollection insDbParamCollection = new DbParamCollection();
			insDbParamCollection.Add("@pPublishDate",parEntArticles.PublishDate);
			insDbParamCollection.Add("@pArticleDescription",parEntArticles.ArticleDescription);
			insDbParamCollection.AddOutput("@pArticleId",DbType.Int32);
			parDbConnector.ExecuteNonQuery("InsertArticles",insDbParamCollection);
			parEntArticles.ArticleId = Convert.ToInt32(insDbParamCollection.GetOutPutParameter().Value);
		}
		public void UpdateArticlesByArticleId(entArticles parEntArticles, DbConnector parDbConnector)
		{
			DbParamCollection insDbParamCollection = new DbParamCollection();
			insDbParamCollection.Add("@pArticleId",parEntArticles.ArticleId);
			
			insDbParamCollection.Add("@pPublishDate",parEntArticles.PublishDate);
			insDbParamCollection.Add("@pArticleDescription",parEntArticles.ArticleDescription);
			parDbConnector.ExecuteNonQuery("UpdateArticlesByArticleId",insDbParamCollection);
		}
		public DataTable SelectArticles(DbConnector parDbConnector)
		{
			
			return parDbConnector.ExecuteDataTable("SelectArticles",null);
		}
		public void SelectArticlesByArticleId(entArticles parEntArticles, DbConnector parDbConnector)
		{
			DbParamCollection insDbParamCollection = new DbParamCollection();
			insDbParamCollection.Add("@pArticleId",parEntArticles.ArticleId);
			DataTable insDataTable = new DataTable();
			insDataTable = parDbConnector.ExecuteDataTable("SelectArticlesByArticleId",insDbParamCollection);
			if (insDataTable.Rows.Count>0)
			{
				if (insDataTable.Rows[0]["ArticleId"]!=DBNull.Value)
				{
					parEntArticles.ArticleId = Convert.ToInt32(insDataTable.Rows[0]["ArticleId"]);
				}
				if (insDataTable.Rows[0]["PublishDate"]!=DBNull.Value)
				{
					parEntArticles.PublishDate = Convert.ToDateTime(insDataTable.Rows[0]["PublishDate"]);
				}
				if (insDataTable.Rows[0]["ArticleDescription"]!=DBNull.Value)
				{
					parEntArticles.ArticleDescription = insDataTable.Rows[0]["ArticleDescription"].ToString();
				}
			}
		}
		
		#endregion
        public DataTable SelectArticlesArchive(DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pLanguageId", CurrentContext.LanguageId);
            return parDbConnector.ExecuteDataTable("SelectArticlesArchive", insDbParamCollection);
        }
        public DataTable SelectArticlesRandom(DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pLanguageId", CurrentContext.LanguageId);
            return parDbConnector.ExecuteDataTable("SelectArticlesRandom", insDbParamCollection);
        }
        public DataTable SelectArticlesByLanguageId(DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pLanguageId", CurrentContext.LanguageId);
            return parDbConnector.ExecuteDataTable("SelectArticlesByLanguageId", insDbParamCollection);
        }
        public DataTable SelectArticlesByLanguageIdAndYearAndMonth(entArticles parEntArticles, DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pLanguageId", CurrentContext.LanguageId);
            insDbParamCollection.Add("@pYear", parEntArticles.PublishDate.Year);
            insDbParamCollection.Add("@pMonth", parEntArticles.PublishDate.Month);
            return parDbConnector.ExecuteDataTable("SelectArticlesByLanguageIdAndYearAndMonth", insDbParamCollection);
        }
        public DataTable SelectArticlesByLanguageIdAndCategoryId(int categoryId, DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pLanguageId", CurrentContext.LanguageId);
            insDbParamCollection.Add("@pCategoryId", categoryId);
            return parDbConnector.ExecuteDataTable("SelectArticlesByLanguageIdAndCategoryId", insDbParamCollection);
        }
        public DataTable SelectArticlesTopRead(DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pLanguageId", CurrentContext.LanguageId);
            return parDbConnector.ExecuteDataTable("SelectArticlesTopRead", insDbParamCollection);
        }
        public DataTable SelectArticlesLatestMainPage(DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pLanguageId", CurrentContext.LanguageId);
            return parDbConnector.ExecuteDataTable("SelectArticlesLatestMainPage", insDbParamCollection);
        }
        public DataTable SelectArticlesByDateMainPage(entArticles parEntArticles, DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pLanguageId", CurrentContext.LanguageId);
            insDbParamCollection.Add("@pPublishDate", parEntArticles.PublishDate);
            return parDbConnector.ExecuteDataTable("SelectArticlesByDateMainPage", insDbParamCollection);
        }
	}
}